package com.motu.monstercity.module.common.network;

import com.google.protobuf.ByteString;
import com.motu.monstercity.protocol.Base.RspBase;
import com.motu.monstercity.protocol.CmdEnum.EnumCmdID;
import io.vertx.core.buffer.Buffer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class DataEncoded {

    public static Buffer encode(int cmdCode,byte error,byte data[],int messageId){
        Buffer buffer = Buffer.buffer();
        int len = (data.length+15);
        buffer.appendInt(len);
        buffer.appendInt(cmdCode);
        byte encrypt = 0;
        byte compress = 0;
        buffer.appendByte(encrypt);
        buffer.appendByte(compress);
        buffer.appendByte(error);
        buffer.appendInt(messageId);
        buffer.appendBytes(data);
        return buffer;
    }
    /***
     * 对上行数据进行encode
     * @param cmdCode
     * @param data
     * @return
     */
    public static Buffer encodeRequest(int cmdCode,byte data[]){
        Buffer buffer = Buffer.buffer();
        short len = (short)(data.length+15);
        buffer.appendShort(len);
        buffer.appendInt(cmdCode);
        byte encrypt = 0;
        byte compress = 0;
        byte language = 0;
        buffer.appendByte(encrypt);
        buffer.appendByte(compress);
        buffer.appendByte(language);
        buffer.appendInt(0);//保留字段
        buffer.appendInt(0);//字段
        buffer.appendBytes(data);
        return buffer;
    }
}
